<?php
namespace app\index\controller;

use phpmailer\phpmailer;
use think\Controller;
use think\Db;
use think\Config;

class Base extends Controller
{

    public function demo(){
        return '测试数据';
    }
    //验证session是否存在
    public function baseindex()
    {
        session_start();
        if (!isset($_SESSION['ch_name'])) {
            $this->redirect('Login/index');
        }
        /*else{
            $session=Db::table('oa_user_session')->where(['user_id'=>$_SESSION['id']])->find();
            if (!empty($session)){
                $data=time();
                //每操作一次sessionid 退出登录时间刷新一次（此时时间为当前时间+900s  即sessionid失效时间和（不作操作自动退出or直接关闭浏览器时默认的退出时间））
                if ($data<$session['sessionid']){
                    //sessionid 时间
                    $datas=$data+900;
                    //退出时间
                    $datass=date('Y-m-d H:i:s', $datas);
                    $where['user_id']=$_SESSION['id'];
                    $where['enter_time'] = $_SESSION['time'];
                    Db::table('oa_user_session')->where(['user_id'=>$where['user_id']])->update(['sessionid'=>$datas]);
                    Db::table('oa_user_entertime')->where($where)->update(['end_time'=>$datass]);
                }else{
                    $this->redirect('Login/admin');
                }
            }else{
                $this->redirect('Login/admin');
            }
        }*/
    }

    //验证邮箱（前台）
    public function getEmail()
    {
        //验证邮箱（前台）
        if (isset($_POST['email'])) {
            $str = input('post.email');
            $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
            if (preg_match($pattern, $str)) {
                return 1;
            } else {
                return 0;
            }
        }
    }

    //验证邮箱(后台)
    public function getEmaila($str)
    {
        //验证邮箱(后台)
        $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
        if (preg_match($pattern, $str)) {
            return 1;
        } else {
            return 0;
        }
    }

    //发送邮件
    //发送邮件
    public function email($email,$rand,$ch_name)
    {
        //发送邮件
        //$rand=12345;
        //$toemail = 'cw1993teemo@163.com';//定义收件人的邮箱
        $mail = new PHPMailer();
        $mail->isSMTP();// 使用SMTP服务
        $mail->CharSet = "utf8";// 编码格式为utf8，不设置编码的话，中文会出现乱码
        $mail->Host = "smtp.163.com";// 发送方的SMTP服务器地址
        $mail->SMTPAuth = true;// 是否使用身份验证
        $mail->Username = "cw1993teemo@163.com";// 发送方的QQ邮箱用户名，就是自己的邮箱名
        $mail->Password = "asd18354682311";// 发送方的邮箱密码，不是登录密码,是qq的第三方授权登录码,要自己去开启,在邮箱的设置->账户->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务 里面
        $mail->SMTPSecure = "ssl";// 使用ssl协议方式,
        $mail->Port = 465;// QQ邮箱的ssl协议方式端口号是465/587

        $mail->setFrom("cw1993teemo@163.com",'挪宝新能源集团');// 设置发件人信息，如邮件格式说明中的发件人,
        $mail->addAddress($email,$ch_name);// 设置收件人信息，如邮件格式说明中的收件人
        $mail->addReplyTo("cw1993teemo@163.com", "Reply");// 设置回复人信息，指的是收件人收到邮件后，如果要回复，回复邮件将发送到的邮箱地址
        //$mail->addCC("xxx@163.com");// 设置邮件抄送人，可以只写地址，上述的设置也可以只写地址(这个人也能收到邮件)
        //$mail->addBCC("xxx@163.com");// 设置秘密抄送人(这个人也能收到邮件)
        //$mail->addAttachment("bug0.jpg");// 添加附件


        $mail->Subject = "修改密码";// 邮件标题
        //$mail->Body = $rand;// 邮件正文
        $mail->Body =  '你好：你的验证码为' . $rand . '，5分钟之内有效，若验证码错误，5分钟之后可重新获取';// 邮件正文
        $mail->AltBody = "This is the plain text纯文本";// 这个是设置纯文本方式显示的正文内容，如果不支持Html方式，就会用到这个，基本无用
        //return 111;
        if (!$mail->send()) {// 发送邮件
            return 0;
            //echo "Message could not be sent.";
            //echo "Mailer Error: ".$mail->ErrorInfo;// 输出错误信息
        } else {
            return 1;
            /*echo '发送成功';*/
        }
    }
//    public function email($toemail,$rand,$ch_name)
//    {
//        //发送邮件
//        //$rand=12345;
//        //return 3232;
//        //$toemail = 'cw1993teemo@163.com';//定义收件人的邮箱
//        $mail = new PHPMailer();
//        $mail->isSMTP();// 使用SMTP服务
//        $mail->CharSet = "utf8";// 编码格式为utf8，不设置编码的话，中文会出现乱码
//        $mail->Host = "smtp.163.com";// 发送方的SMTP服务器地址
//        $mail->SMTPAuth = true;// 是否使用身份验证
//        $mail->Username = "cw1993teemo@163.com";// 发送方的QQ邮箱用户名，就是自己的邮箱名
//        $mail->Password = "asd18354682311";// 发送方的邮箱密码，不是登录密码,是qq的第三方授权登录码,要自己去开启,在邮箱的设置->账户->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务 里面
//        $mail->SMTPSecure = "ssl";// 使用ssl协议方式,
//        $mail->Port = 465;// QQ邮箱的ssl协议方式端口号是465/587
//
//        $mail->setFrom("cw1993teemo@163.com",'挪宝新能源集团');// 设置发件人信息，如邮件格式说明中的发件人,
//        $mail->addAddress($toemail,$ch_name);// 设置收件人信息，如邮件格式说明中的收件人
//        $mail->addReplyTo("cw1993teemo@163.com", "Reply");// 设置回复人信息，指的是收件人收到邮件后，如果要回复，回复邮件将发送到的邮箱地址
//        //$mail->addCC("xxx@163.com");// 设置邮件抄送人，可以只写地址，上述的设置也可以只写地址(这个人也能收到邮件)
//        //$mail->addBCC("xxx@163.com");// 设置秘密抄送人(这个人也能收到邮件)
//        //$mail->addAttachment("bug0.jpg");// 添加附件
//
//        //$mail->Subject = "=?utf-8?B?".base64_encode("修改密码")."?=";
//        $mail->Subject = "修改密码";// 邮件标题
//        $mail->Body =  '你好：你的验证码为' . $rand . '，5分钟之内有效，若验证码错误，5分钟之后可重新获取';// 邮件正文
//        $mail->AltBody = "This is the plain text纯文本";// 这个是设置纯文本方式显示的正文内容，如果不支持Html方式，就会用到这个，基本无用
//
//        if (!$mail->send()) {// 发送邮件
//            //return 0;
//            //echo "Message could not be sent.";
//            return "Mailer Error: ".$mail->ErrorInfo;// 输出错误信息
//        } else {
//            return 2223;
//            /*echo '发送成功';*/
//        }
//    }

    public function liandong_a()
    {
        //第一级数据
        $result = Db::table('oa_region')->where('state=1')->select();
        $res['datalist'] = $result;
        return $res;
    }

    public function liandong_b($region_id)
    {
        $result = Db::table('oa_branch')->where('state=1 and region_id=' . $region_id)->select();
        $res['datalist'] = $result;
        return $res;
    }

    //验证是否为座机号
    public function number($num)
    {
        //验证是否为座机号
        if (preg_match("/^([0-9]{3,4}-)?[0-9]{7,8}$/", $num)) {
            return 1;
        } else {
            return 0;
        }
    }

    //还未启用
    public function cache_clear()
    {
        $this->baseindex();
        $wnere['state'] = 1;
        $arr = Db::table('oa_role_jurisdiction')->where('role_id=1')->where('jurisdiction_id=1')->update($wnere);
        dump($arr);
        die;
    }

    public function liandong_c()
    {
        $this->baseindex();
        //第一级数据
        $result = Db::table('oa_region')->where('state=1 or state=2')->select();
        $res['datalist'] = $result;
        return $res;
    }

    /**
     * @param $region_id
     * @return mixed
     */
    public function liandong_d($region_id)
    {
        //$region_id=2;
        $region=Db::table('oa_region')->where('id='.$region_id)->find();
        if ($region['state'] == 2){
            $result = Db::table('oa_branch')->where('state=1 or state=2')->select();
            //dump($result);die;
            $res['datalist'] = $result;
            return $res;
        }else{
            $result_region_id = Db::table('oa_branch')->where('state=1')->where('region_id=' . $region_id)->select();
            $result_all = Db::table('oa_branch')->where('state=2')->find();
            $result[]=$result_all;
            foreach ($result_region_id as $key=>$value){
                $result[]=$value;
            }
            $res['datalist'] = $result;
            return $res;
        }


    }

    public function role()
    {
        if ($_POST['role'] == 'role' && isset($_POST['role'])) {
            $role = Db::table('oa_role')->select();
            return $role;
        } else {
            return 0;
        }

    }

    //报销审批审批流程数据处理
    public function flow_reimbursement_apply(){
        //审批流程数据处理
        $ch_name = $_SESSION['ch_name'];
        //$ch_name = '测试';
        $user_id = $_SESSION['id'];
        //$user_id = 66;
        $res = Db::table('oa_user')->field('region_id,branch_id')->where(['ch_name' => $ch_name, 'id' => $user_id])
            ->find();
        $bill_type_id = 1;
        $where = "bill_type_id=" . $bill_type_id . " and ( ( region_id=" . $res['region_id']
            . " and ( branch_id=" . $res['branch_id'] . " or branch_id =1 ) ) 
                or (( region_id = 2 ) and ( branch_id = 1 or branch_id= " . $res['branch_id'] . ")) )";
        $flow = Db::table('oa_flow')->where($where)->select();
        //dump($flow);die;
        foreach ($flow as $key => $value) {
            if (!empty($value['first'])) {
                $first = Db::table('oa_role')->where('id=' . $value['first'])->find();
                $flow[$key]['first'] = $first['role'];
                $flow[$key]['flow'] = $first['role'];
            } else {
                unset($flow[$key]['first']);
            }
            if (!empty($value['second'])) {
                $second = Db::table('oa_role')->where('id=' . $value['second'])->find();
                $flow[$key]['second'] = $second['role'];
                $flow[$key]['flow'] .= '->' . $second['role'];
            } else {
                unset($flow[$key]['second']);
            }
            if (!empty($value['third'])) {
                $third = Db::table('oa_role')->where('id=' . $value['third'])->find();
                $flow[$key]['third'] = $third['role'];
                $flow[$key]['flow'] .= '->' . $third['role'];
            } else {
                unset($flow[$key]['third']);
            }
            if (!empty($value['fourth'])) {
                $fourth = Db::table('oa_role')->where('id=' . $value['fourth'])->find();
                $flow[$key]['fourth'] = $fourth['role'];
                $flow[$key]['flow'] .= '->' . $fourth['role'];
            } else {
                unset($flow[$key]['fourth']);
            }
            if (!empty($value['fifth'])) {
                $fifth = Db::table('oa_role')->where('id=' . $value['fifth'])->find();
                $flow[$key]['fifth'] = $fifth['role'];
                $flow[$key]['flow'] .= '->' . $fifth['role'];
            } else {
                unset($flow[$key]['fifth']);
            }
            if (!empty($value['sixth'])) {
                $sixth = Db::table('oa_role')->where('id=' . $value['sixth'])->find();
                $flow[$key]['sixth'] = $sixth['role'];
                $flow[$key]['flow'] .= '->' . $sixth['role'];
            } else {
                unset($flow[$key]['sixth']);
            }
            if (!empty($value['seventh'])) {
                $seventh = Db::table('oa_role')->where('id=' . $value['seventh'])->find();
                $flow[$key]['seventh'] = $seventh['role'];
                $flow[$key]['flow'] .= '->' . $seventh['role'];
            } else {
                unset($flow[$key]['seventh']);
            }
            if (!empty($value['eighth'])) {
                $eighth = Db::table('oa_role')->where('id=' . $value['eighth'])->find();
                $flow[$key]['eighth'] = $eighth['role'];
                $flow[$key]['flow'] .= '->' . $eighth['role'];
            } else {
                unset($flow[$key]['eighth']);
            }
            if (!empty($value['ninth'])) {
                $ninth = Db::table('oa_role')->where('id=' . $value['ninth'])->find();
                $flow[$key]['ninth'] = $ninth['role'];
                $flow[$key]['flow'] .= '->' . $ninth['role'];
            } else {
                unset($flow[$key]['ninth']);
            }
            if (!empty($value['tenth'])) {
                $tenth = Db::table('oa_role')->where('id=' . $value['tenth'])->find();
                $flow[$key]['tenth'] = $tenth['role'];
                $flow[$key]['flow'] .= '->' . $tenth['role'];
            } else {
                unset($flow[$key]['tenth']);
            }
        }
        return $flow;
    }

    //付款申请审批流程数据处理
    public function flow_payment_application_form(){
        //审批流程数据处理
        $ch_name = $_SESSION['ch_name'];
        $user_id = $_SESSION['id'];
        $res = Db::table('oa_user')->field('region_id,branch_id')->where(['ch_name' => $ch_name, 'id' => $user_id])
            ->find();
        $bill_type_id = 2;
        $where = "bill_type_id=" . $bill_type_id . " and ( ( region_id=" . $res['region_id']
            . " and ( branch_id=" . $res['branch_id'] . " or branch_id =1 ) ) 
                or ( region_id = 2 ) and ( branch_id = 1 or branch_id= " . $res['branch_id'] . ") )";
        $flow = Db::table('oa_flow')->where($where)->select();
        foreach ($flow as $key => $value) {
            if (!empty($value['first'])) {
                $first = Db::table('oa_role')->where('id=' . $value['first'])->find();
                $flow[$key]['first'] = $first['role'];
                $flow[$key]['flow'] = $first['role'];
            } else {
                unset($flow[$key]['first']);
            }
            if (!empty($value['second'])) {
                $second = Db::table('oa_role')->where('id=' . $value['second'])->find();
                $flow[$key]['second'] = $second['role'];
                $flow[$key]['flow'] .= '->' . $second['role'];
            } else {
                unset($flow[$key]['second']);
            }
            if (!empty($value['third'])) {
                $third = Db::table('oa_role')->where('id=' . $value['third'])->find();
                $flow[$key]['third'] = $third['role'];
                $flow[$key]['flow'] .= '->' . $third['role'];
            } else {
                unset($flow[$key]['third']);
            }
            if (!empty($value['fourth'])) {
                $fourth = Db::table('oa_role')->where('id=' . $value['fourth'])->find();
                $flow[$key]['fourth'] = $fourth['role'];
                $flow[$key]['flow'] .= '->' . $fourth['role'];
            } else {
                unset($flow[$key]['fourth']);
            }
            if (!empty($value['fifth'])) {
                $fifth = Db::table('oa_role')->where('id=' . $value['fifth'])->find();
                $flow[$key]['fifth'] = $fifth['role'];
                $flow[$key]['flow'] .= '->' . $fifth['role'];
            } else {
                unset($flow[$key]['fifth']);
            }
            if (!empty($value['sixth'])) {
                $sixth = Db::table('oa_role')->where('id=' . $value['sixth'])->find();
                $flow[$key]['sixth'] = $sixth['role'];
                $flow[$key]['flow'] .= '->' . $sixth['role'];
            } else {
                unset($flow[$key]['sixth']);
            }
            if (!empty($value['seventh'])) {
                $seventh = Db::table('oa_role')->where('id=' . $value['seventh'])->find();
                $flow[$key]['seventh'] = $seventh['role'];
                $flow[$key]['flow'] .= '->' . $seventh['role'];
            } else {
                unset($flow[$key]['seventh']);
            }
            if (!empty($value['eighth'])) {
                $eighth = Db::table('oa_role')->where('id=' . $value['eighth'])->find();
                $flow[$key]['eighth'] = $eighth['role'];
                $flow[$key]['flow'] .= '->' . $eighth['role'];
            } else {
                unset($flow[$key]['eighth']);
            }
            if (!empty($value['ninth'])) {
                $ninth = Db::table('oa_role')->where('id=' . $value['ninth'])->find();
                $flow[$key]['ninth'] = $ninth['role'];
                $flow[$key]['flow'] .= '->' . $ninth['role'];
            } else {
                unset($flow[$key]['ninth']);
            }
            if (!empty($value['tenth'])) {
                $tenth = Db::table('oa_role')->where('id=' . $value['tenth'])->find();
                $flow[$key]['tenth'] = $tenth['role'];
                $flow[$key]['flow'] .= '->' . $tenth['role'];
            } else {
                unset($flow[$key]['tenth']);
            }
        }
        return $flow;
    }

    //请假申请审批流程数据处理
    public function flow_leaves(){
        $ch_name = $_SESSION['ch_name'];
        $user_id = $_SESSION['id'];
        $res = Db::table('oa_user')->field('region_id,branch_id')->where(['ch_name' => $ch_name, 'id' => $user_id])
            ->find();
        $bill_type_id = 4;
        $where = "bill_type_id=" . $bill_type_id . " and ( ( region_id=" . $res['region_id']
            . " and ( branch_id=" . $res['branch_id'] . " or branch_id =1 ) ) 
                or ( region_id = 2 ) and ( branch_id = 1 or branch_id= " . $res['branch_id'] . ") )";
        $flow = Db::table('oa_flow')->where($where)->select();
        foreach ($flow as $key => $value) {
            if (!empty($value['first'])) {
                $first = Db::table('oa_role')->where('id=' . $value['first'])->find();
                $flow[$key]['first'] = $first['role'];
                $flow[$key]['flow'] = $first['role'];
            } else {
                unset($flow[$key]['first']);
            }
            if (!empty($value['second'])) {
                $second = Db::table('oa_role')->where('id=' . $value['second'])->find();
                $flow[$key]['second'] = $second['role'];
                $flow[$key]['flow'] .= '->' . $second['role'];
            } else {
                unset($flow[$key]['second']);
            }
            if (!empty($value['third'])) {
                $third = Db::table('oa_role')->where('id=' . $value['third'])->find();
                $flow[$key]['third'] = $third['role'];
                $flow[$key]['flow'] .= '->' . $third['role'];
            } else {
                unset($flow[$key]['third']);
            }
            if (!empty($value['fourth'])) {
                $fourth = Db::table('oa_role')->where('id=' . $value['fourth'])->find();
                $flow[$key]['fourth'] = $fourth['role'];
                $flow[$key]['flow'] .= '->' . $fourth['role'];
            } else {
                unset($flow[$key]['fourth']);
            }
            if (!empty($value['fifth'])) {
                $fifth = Db::table('oa_role')->where('id=' . $value['fifth'])->find();
                $flow[$key]['fifth'] = $fifth['role'];
                $flow[$key]['flow'] .= '->' . $fifth['role'];
            } else {
                unset($flow[$key]['fifth']);
            }
            if (!empty($value['sixth'])) {
                $sixth = Db::table('oa_role')->where('id=' . $value['sixth'])->find();
                $flow[$key]['sixth'] = $sixth['role'];
                $flow[$key]['flow'] .= '->' . $sixth['role'];
            } else {
                unset($flow[$key]['sixth']);
            }
            if (!empty($value['seventh'])) {
                $seventh = Db::table('oa_role')->where('id=' . $value['seventh'])->find();
                $flow[$key]['seventh'] = $seventh['role'];
                $flow[$key]['flow'] .= '->' . $seventh['role'];
            } else {
                unset($flow[$key]['seventh']);
            }
            if (!empty($value['eighth'])) {
                $eighth = Db::table('oa_role')->where('id=' . $value['eighth'])->find();
                $flow[$key]['eighth'] = $eighth['role'];
                $flow[$key]['flow'] .= '->' . $eighth['role'];
            } else {
                unset($flow[$key]['eighth']);
            }
            if (!empty($value['ninth'])) {
                $ninth = Db::table('oa_role')->where('id=' . $value['ninth'])->find();
                $flow[$key]['ninth'] = $ninth['role'];
                $flow[$key]['flow'] .= '->' . $ninth['role'];
            } else {
                unset($flow[$key]['ninth']);
            }
            if (!empty($value['tenth'])) {
                $tenth = Db::table('oa_role')->where('id=' . $value['tenth'])->find();
                $flow[$key]['tenth'] = $tenth['role'];
                $flow[$key]['flow'] .= '->' . $tenth['role'];
            } else {
                unset($flow[$key]['tenth']);
            }
        }
        return $flow;
    }

    //合同申请审批流程数据处理
    public function flow_contract_form(){
        $ch_name = $_SESSION['ch_name'];
        $user_id = $_SESSION['id'];
        $res = Db::table('oa_user')->field('region_id,branch_id')->where(['ch_name' => $ch_name, 'id' => $user_id])
            ->find();
        $bill_type_id = 8;
        $where = "bill_type_id=" . $bill_type_id . " and ( ( region_id=" . $res['region_id']
            . " and ( branch_id=" . $res['branch_id'] . " or branch_id =1 ) ) 
                or ( region_id = 2 ) and ( branch_id = 1 or branch_id= " . $res['branch_id'] . ") )";
        $flow = Db::table('oa_flow')->where($where)->select();
        //return $flow;
        foreach ($flow as $key => $value) {
            if (!empty($value['first'])) {
                $first = Db::table('oa_role')->where('id=' . $value['first'])->find();
                $flow[$key]['first'] = $first['role'];
                $flow[$key]['flow'] = $first['role'];
            } else {
                unset($flow[$key]['first']);
            }
            if (!empty($value['second'])) {
                $second = Db::table('oa_role')->where('id=' . $value['second'])->find();
                $flow[$key]['second'] = $second['role'];
                $flow[$key]['flow'] .= '->' . $second['role'];
            } else {
                unset($flow[$key]['second']);
            }
            if (!empty($value['third'])) {
                $third = Db::table('oa_role')->where('id=' . $value['third'])->find();
                $flow[$key]['third'] = $third['role'];
                $flow[$key]['flow'] .= '->' . $third['role'];
            } else {
                unset($flow[$key]['third']);
            }
            if (!empty($value['fourth'])) {
                $fourth = Db::table('oa_role')->where('id=' . $value['fourth'])->find();
                $flow[$key]['fourth'] = $fourth['role'];
                $flow[$key]['flow'] .= '->' . $fourth['role'];
            } else {
                unset($flow[$key]['fourth']);
            }
            if (!empty($value['fifth'])) {
                $fifth = Db::table('oa_role')->where('id=' . $value['fifth'])->find();
                $flow[$key]['fifth'] = $fifth['role'];
                $flow[$key]['flow'] .= '->' . $fifth['role'];
            } else {
                unset($flow[$key]['fifth']);
            }
            if (!empty($value['sixth'])) {
                $sixth = Db::table('oa_role')->where('id=' . $value['sixth'])->find();
                $flow[$key]['sixth'] = $sixth['role'];
                $flow[$key]['flow'] .= '->' . $sixth['role'];
            } else {
                unset($flow[$key]['sixth']);
            }
            if (!empty($value['seventh'])) {
                $seventh = Db::table('oa_role')->where('id=' . $value['seventh'])->find();
                $flow[$key]['seventh'] = $seventh['role'];
                $flow[$key]['flow'] .= '->' . $seventh['role'];
            } else {
                unset($flow[$key]['seventh']);
            }
            if (!empty($value['eighth'])) {
                $eighth = Db::table('oa_role')->where('id=' . $value['eighth'])->find();
                $flow[$key]['eighth'] = $eighth['role'];
                $flow[$key]['flow'] .= '->' . $eighth['role'];
            } else {
                unset($flow[$key]['eighth']);
            }
            if (!empty($value['ninth'])) {
                $ninth = Db::table('oa_role')->where('id=' . $value['ninth'])->find();
                $flow[$key]['ninth'] = $ninth['role'];
                $flow[$key]['flow'] .= '->' . $ninth['role'];
            } else {
                unset($flow[$key]['ninth']);
            }
            if (!empty($value['tenth'])) {
                $tenth = Db::table('oa_role')->where('id=' . $value['tenth'])->find();
                $flow[$key]['tenth'] = $tenth['role'];
                $flow[$key]['flow'] .= '->' . $tenth['role'];
            } else {
                unset($flow[$key]['tenth']);
            }
        }
        return $flow;
    }

    //把数字转化成大写
    public function num_to_rmb($num){
        //$num=12346566;
        $c1 = "零壹贰叁肆伍陆柒捌玖";
        $c2 = "分角元拾佰仟万拾佰仟亿";
        //精确到分后面就不要了，所以只留两个小数位
        $num = round($num, 2);
        //将数字转化为整数
        $num = $num * 100;
        if (strlen($num) > 10) {
            return "金额太大，请检查";
        }
        $i = 0;
        $c = "";
        while (1) {
            if ($i == 0) {
                //获取最后一位数字
                $n = substr($num, strlen($num)-1, 1);
            } else {
                $n = $num % 10;
            }
            //每次将最后一位数字转化为中文
            $p1 = substr($c1, 3 * $n, 3);
            $p2 = substr($c2, 3 * $i, 3);
            if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
                $c = $p1 . $p2 . $c;
            } else {
                $c = $p1 . $c;
            }
            $i = $i + 1;
            //去掉数字最后一位了
            $num = $num / 10;
            $num = (int)$num;
            //结束循环
            if ($num == 0) {
                break;
            }
        }
        $j = 0;
        $slen = strlen($c);
        while ($j < $slen) {
            //utf8一个汉字相当3个字符
            $m = substr($c, $j, 6);
            //处理数字中很多0的情况,每次循环去掉一个汉字“零”
            if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
                $left = substr($c, 0, $j);
                $right = substr($c, $j + 3);
                $c = $left . $right;
                $j = $j-3;
                $slen = $slen-3;
            }
            $j = $j + 3;
        }
        //这个是为了去掉类似23.0中最后一个“零”字
        if (substr($c, strlen($c)-3, 3) == '零') {
            $c = substr($c, 0, strlen($c)-3);
        }
        //将处理的汉字加上“整”
        if (empty($c)) {
            return "零元整";
        }else{
            return $c . "整";
        }
    }

    /**
     * @param $phone
     * @return int
     * 添加员工时验证手机号唯一
     * @author  曹旺
     * @data  11:00
     */
    public function verify_phone($phone){
        $UserModel=new \app\index\model\User();
        $res=$UserModel->where(['tel'=>$phone,'state'=>1])->select()->toArray();
        if (count($res)>0){
            return 0;
        }else{
            return 1;
        }
    }

    /**
     * @param $email
     * @return int
     * 添加员工时验证邮箱唯一
     * @author  曹旺
     * @data  11:01
     */
    public function verify_email($email){
        $UserModel=new \app\index\model\User();
        $res=$UserModel->where(['email'=>$email,'state'=>1])->select()->toArray();
        if (count($res)>0){
            return 0;
        }else{
            return 1;
        }
    }

    /**
     * @param $user_id
     * @param $phone
     * @return int
     * 修改员工信息时验证手机唯一
     * @author  曹旺
     * @data  11:18
     */
    public function save_verify_phone($user_id,$phone){
        $UserModel=new \app\index\model\User();
        $res=$UserModel->where(['tel'=>$phone])->select()->toArray();
        if (count($res)){
            if (count($res)==1 && $res[0]['id']==$user_id){
                return 1;
            }else{
                return 0;
            }
        }else{
            return 1;
        }
    }

    /**
     * @param $user_id
     * @param $email
     * @return int
     * 修改员工信息时验证邮箱唯一
     * @author  曹旺
     * @data  11:17
     */
    public function save_verify_email($user_id,$email){
        $UserModel=new \app\index\model\User();
        $res=$UserModel->where(['email'=>$email])->select()->toArray();
        if (count($res)){
            if (count($res)==1 && $res[0]['id']==$user_id){
                return 1;
            }else{
                return 0;
            }
        }else{
            return 1;
        }
    }


}